﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using FBGraph.Models;

namespace FBGraph.Api.Tests
{
    [TestClass]
    public class PageConverterTests
    {
        [TestMethod]
        public void DeserializesStandardProperties()
        {
            var json = "{ \"genre\": \"art-folk-polka-jazz-metal-fusion\", \"id\": 1240953, \"category\": \"musicians\", \"artists_we_like\": \"Radiohead\" }";
            var page = JsonConvert.DeserializeObject<Page>(json);

            Assert.AreEqual(1240953, page.Id);
            Assert.AreEqual("musicians", page.Category);
        }

        [TestMethod]
        public void DeserializesDetailsProperties()
        {
            var json = "{ \"genre\": \"art-folk-polka-jazz-metal-fusion\", \"id\": 1240953, \"category\": \"musicians\", \"artists_we_like\": \"Radiohead\" }";
            var page = JsonConvert.DeserializeObject<Page>(json);

            Assert.AreEqual("art-folk-polka-jazz-metal-fusion", page.Details["genre"]);
            Assert.AreEqual("Radiohead", page.Details["artists_we_like"]);
        }

        [TestMethod]
        public void DeserializesArrayProperties()
        {
            var json = "{   \"data\": [      {         \"id\": \"117932401578500\",         \"name\": \"making the goodies, raising the baby. typically not in that order.\",         \"category\": \"Interest\",         \"link\": \"http://www.facebook.com/pages/making-the-goodies-raising-the-baby-typically-not-in-that-order/117932401578500\",         \"fan_count\": 1      }   ]}";
            var result = JsonConvert.DeserializeObject<PagedResult<Page>>(json);

            Assert.IsTrue(result != null, "result was null");
            Assert.IsTrue(result.Data != null, "data array was null");
            Assert.AreEqual(1, result.Data.Length);
            Assert.AreEqual(117932401578500, result.Data[0].Id);
        }
    }
}